This article is about how to set up git repository and how to mange porject with git
Set up git project
Let say, I am making a “helloworld” project and set git to manage it.
Below show how to use git to manage this “helloworld” project
- Make a dir and get into it
1 | mkdir helloworld |
- Initialize git and project
1 | Set a README.md |
Daily update
In daily workflow, we must update the project first then modify the content, after day of work, we need to push all the commit to server
- Update the project
1 | git pull |
Then we can modify the file and happy coding, let say, if we modify a.py, we need to commit and push the result
1 | -a mean all, commit all the change |
Branch management
- For coorperated project, it’s recommended to make the project into many branches based on different functions, then merge the branches after all the function finished
1 | Make a new branch based on current code |
- After finishing all the coding, we need to merge feature_x to master
1 | Get into master |
- After finish merging all the functions, it is time to set a deliver tag for celebration , we can do with by tagging current version
1 | First, get the verion num for current version |
Time machine
- Some time, we may make some mistakes in coding, if you want to roll back to version before last push, you can run command
1 | git checkout --<filename> |
- Or if you want current branch reset and set as another branch, you can run this command
1 | git fetch orign |
Git tools
There are many tricks for making git experience better
- Use git with interation mode
1 | git add -i |
- Use git in color mode
1 | git config color.ui true |
- Make git log into one line
1 | git config fomat.pretty oneline |
- Use GUI of git
1 | gitk |
- Analyse the log from git
1 | Get log info |